unit PootcherOptions;

interface

  type
    TPootcherOptions = class
      private
        function GetUpdaterURL() : Widestring;
        function IsDebug() : Boolean;
      public
        property UpdaterPage : Widestring read GetUpdaterURL;
        property Debug : Boolean read IsDebug;
    end;

  var
    Options : TPootcherOptions;

implementation

  uses
    SysUtils, Windows, Dialogs;

  function TPootcherOptions.GetUpdaterURL() : Widestring;
  const
    {$J+}URL : Widestring = '';{$J-}
  var
    Buffer : Array[0..2082] of Widechar;
    StringResource : Integer;
  begin
    if URL = '' then
    begin
      //Check if URL was passed as parameter first
      if ParamCount > 0 then
        if Length(ParamStr(ParamCount)) > 0 then
          if AnsiPos('-', ParamStr(ParamCount)) <> 1 then
            URL := ParamStr(ParamCount);
      if URL = '' then
      begin
        //Grab URL from resource otherwise page is blank
        StringResource := LoadString(hInstance, 1000, Buffer, sizeof(Buffer));
        if StringResource <> 0 then URL := Buffer
        else URL := 'about:blank';
      end;
    end;
    Result := URL;
  end;

  function TPootcherOptions.IsDebug() : Boolean;
  var
    i : Integer;
  begin
    Result := false;
    for i := 1 to ParamCount do
      if Lowercase(ParamStr(i)) = '-debug' then
      begin
        Result := true;
        break;
      end;
  end;

initialization
  Options := TPootcherOptions.Create();

finalization
  FreeAndNil(Options);

end.
